package com.example.lte.service;

import com.example.lte.po.SystemInfo;
import com.example.lte.repo.OperationLogRepo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author lzh
 * @date 2020/11/6 - 19:03
 */
@Slf4j
@Service
public class ScheduleService {

    //--------使用场景2----实现服务器主动向客户端推送消息---------------------------------------------------------------------
    @Autowired
    private SimpMessagingTemplate simpMessagingTemplate;


    @Resource
    private OperationLogRepo operationLogRepo;


    //广播推送消息
//    @Scheduled(fixedRate = 10000)
    //为了测试，定时10S执行这个方法，向客户端推送
    @Scheduled(fixedRate = 10000)
    public void sendTopicMessage() {
//        System.out.println("后台广播推送！");
        //convertAndSend
        //参数一：客户端监听指定通道时，设定的访问服务器的URL
        //参数二：发送的消息（可以是对象、字符串等等
        simpMessagingTemplate.convertAndSend("/topic/SystemInfo", SystemInfo.revertSystem());
    }


    @Scheduled(fixedRate = 50000)
    public void delDirtyData(){
//        log.info("删除脏数据!");
        operationLogRepo.deleteByAccountIsNull();
    }



}
